package com.example.huhaichao.music.database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBService extends SQLiteOpenHelper
{
	private final static int DATABASE_VERSION = 1;
	private final static String DATABASE_NAME = "Information.db";
	private final static String sql = "create table Musics("+"_id integer primary key autoincrement,"
			+ "musicUrl text)";
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		db.execSQL(sql);
		//db.execSQL("insert into Musics (musicUrl)values(?)", new String[] { "测试数据语句"});
	}

	public DBService(Context context)
	{
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
	}

	public Cursor myQuery(String sql, String[] args)
	{
		SQLiteDatabase db = this.getReadableDatabase();
		Cursor cursor = db.rawQuery(sql, args);
		return cursor;
	}

	public void myInsert(String sql, String[] args){
		SQLiteDatabase db = this.getWritableDatabase();
		db.execSQL(sql,args);
	}

	public void myDelete(String url){
		SQLiteDatabase db = this.getWritableDatabase();
		db.delete("Musics"," musicUrl= ?",new String[]{url});

	}
}
